package moe.net.controller.common;
import jakarta.annotation.Resource;
import moe.net.service.common.FileService;
import moe.net.util.JsonData;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/api/v1/file")
public class FileController {

    @Resource
    private FileService fileService;

    /**
     * 文件上传接口
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public JsonData upload(@RequestParam("file") MultipartFile file){

        String path = fileService.upload(file);

        return JsonData.buildSuccess(path);
    }

    /**
     * 获取临时访问url
     * @param fileUrl
     * @return
     */
    @GetMapping("get_temp_url")
    public JsonData getTempUrl(@RequestParam("fileUrl") String fileUrl){
        String tempAccessFileUrl = fileService.getTempAccessFileUrl(fileUrl);
        return JsonData.buildSuccess(tempAccessFileUrl);
    }
}
